home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / scilab / man / man-part1 / cat6 / optim.6 < prev    next >
Text File  |  1999-09-16  |  6KB  |  199 lines

  1.  
  2.  
  3.  
  4. optim(G)                       Scilab Function                       optim(G)
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11. NAME
  12.   optim - non-linear optimization routine
  13.  
  14. CALLING SEQUENCE
  15.   [f,xopt]=optim(costf,x0)
  16.   [f,[xopt,[gradopt,[work]]]]=optim(costf,[contr],x0,['algo'],[df0,[mem]],
  17.        [work],[stop],['in'])
  18.  
  19. PARAMETERS
  20.  
  21.   costf     : external, i.e Scilab function or string (costf is the cost
  22.             function: see below its calling sequence (Scilab or Fortran)).
  23.  
  24.   x0        : real vector (initial value of variable to be minimized).
  25.  
  26.   f         : value of optimal cost (f=costf(xopt))
  27.  
  28.   xopt      : best value of x found.
  29.  
  30.   contr     : 'b',binf,bsup  with binf and bsup real vectors with same dimen-
  31.             sion as x0. binf and bsup are lower and upper bounds on x.
  32.  
  33.   "algo"    : 'qn' or 'gc' or 'nd' . This string stands for quasi-Newton
  34.             (default), conjugate gradient or non-differentiable respectively.
  35.             Note that 'nd' does not accept bounds on x ).
  36.  
  37.   df0       : real scalar. Guessed decreasing of f at first iteration.
  38.             (df0=1 is the default value).
  39.  
  40.   mem :      integer, number of variables used to approximate the Hessian,
  41.             (algo='gc' or 'nd'). Default value is around 6.
  42.  
  43.   stop      :  sequence of optional parameters controlling the convergence of
  44.             the algorithm.  stop=  'ar',nap, [iter [,epsg [,epsf [,epsx]]]]
  45.  
  46.             "ar"
  47.               : reserved keyword for stopping rule selection defined as fol-
  48.               lows:
  49.  
  50.             nap
  51.               : maximum number of calls to costf allowed.
  52.  
  53.             iter
  54.               : maximum number of iterations allowed.
  55.  
  56.             epsg
  57.               : threshold on gradient norm.
  58.  
  59.             epsf
  60.               : threshold controlling decreasing of f
  61.  
  62.             epsx
  63.               : threshold controlling variation of x.  This vector (possibly
  64.               matrix) of same size as x0 can be used to scale x.
  65.  
  66.   "in"      : reserved  keyword for initialization of parameters used when
  67.             costf in given as a Fortran routine (see below).
  68.  
  69.   gradopt   :  gradient of costf at xopt
  70.  
  71.   work      : working array for hot restart for quasi-Newton method.  This
  72.             array is automatically initialized by optim when optim is
  73.             invoked. It can be used as input parameter to speed-up the calcu-
  74.             lations.
  75.  
  76. DESCRIPTION
  77.   Non-linear optimization routine for programs without constraints or with
  78.   bound constraints:
  79.   min costf(x) w.r.t x.
  80.   costf is an "external" i.e function, or list or Fortran routine (see
  81.   "external").  This external must return f (costf(x)) and g (gradient of
  82.   costf) given x.
  83.  
  84.   If costf is a function, the calling sequence for costf must be:
  85.   [f,g,ind]=costf(x,ind).
  86.   Here, costf is a function which returns f, value (real number) of cost
  87.   function at x, and g, gradient vector of cost function at x.  The variable
  88.   ind is used by optim and is described below.
  89.  
  90.   If ind=2 (resp. 3, 4), costf must provide f (resp. g, f and g).
  91.  
  92.   If ind=1 nothing is computed (used for display purposes only).
  93.  
  94.   On output, ind<0  means that f cannot be evaluated at x and ind=0 inter-
  95.   rupts the optimization.
  96.  
  97.   If costf is a character string, it refers to the name of a Fortran routine
  98.   which must be linked to Scilab (see examples in the routines foptim.f and
  99.   e.g. genros.f in the directory SCIDIR/default)
  100.  
  101.   Dynamic link of Fortran routine is also possible (help link).
  102.  
  103.   Here, the generic calling sequence for the Fortran subroutine is: function
  104.   costf(ind,n,x,f,g,ti,tr,td)
  105.  
  106.   ind has the same meaning as above if set to 0,1,2 but the values ind=10 and
  107.   ind=11 are now valid. These values are used for initializations (see
  108.   below).
  109.  
  110.   n is the dimension of x, x is an n vector, ti,tr,td are working arrays.
  111.  
  112.   The Fortran function costf must return f and the vector g, given x, ind, n,
  113.   ti, tr, td.
  114.  
  115.   If costf is given as a Fortran routine, it is possible to initialize param-
  116.   eters or to send Scilab variables to this routine.
  117.  
  118.   This facility is managed by the parameter 'in.
  119.  
  120.   If the string 'in' is present, initialization is done by Fortran: optim
  121.   makes two calls to the Fortran function costf, once with ind=10 and once
  122.   with ind=11. In this case, for ind=10, costf must set the dimensions nti,
  123.   ntr, ntd of ti, tr, td in the common/nird/nti, ntr, ntd and, for ind=11,
  124.   costf must initialize the vectors ti , tr, td (integer vector, real vector,
  125.   double precision vector respectively).
  126.  
  127.   In the calling sequence of optim, the string 'in' can be replaced by 'ti',
  128.   valti ,'td' , valtd. Then, the Fortran function costf(ind, x, f, g, ti, tr,
  129.   td) is evaluated with ti=valti and td=valtd whatever the value of ind.
  130.   Thus, the Scilab variables valti and valtd (integer vector and real vector)
  131.   are sent to the Fortran function costf.
  132.  
  133.   It is also possible to save the content of of the working arrays ti and td.
  134.   This is possible by adding the strings 'si' and/or 'sd' at the ned of the
  135.   calling sequence of optim.  Then, the output variables must be:
  136.   [f,[x,[g],[to]]],[ti],[td]].
  137.  
  138. EXAMPLES
  139.   xref=[1;2;3];x0=[1;-1;1]
  140.   deff('[f,g,ind]=cost(x,ind)','f=0.5*norm(x-xref)^2,g=x-xref');
  141.   [f,xopt]=optim(cost,x0)      //Simplest call
  142.   [f,xopt,gopt]=optim(cost,x0,'gc')  // By conjugate gradient
  143.   [f,xopt,gopt]=optim(cost,x0,'nd')  //Seen as non differentiable
  144.   [f,xopt,gopt]=optim(cost,'b',[-1;0;2],[0.5;1;4],x0) //  Bounds on x
  145.   [f,xopt,gopt]=optim(cost,'b',[-1;0;2],[0.5;1;4],x0,'gc') //  Bounds on x
  146.   [f,xopt,gopt]=optim(cost,'b',[-1;0;2],[0.5;1;4],x0,'gc','ar',3)
  147.   // Here, 3 calls to cost are allowed.
  148.   //Now calling the Fortran subroutine "genros.f" in SCIDIR/default
  149.   // (see also the interface foptim.f)
  150.   [f,xopt,gopt]=optim('genros',[1;2;3])    //Rosenbrock's function
  151.  
  152. SEE ALSO
  153.   external, quapro, linpro
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.